package com.bigShen.pattern.singleton.main;

import com.bigShen.pattern.singleton.regist.BeanFactory;

import java.util.concurrent.CountDownLatch;

/**
 * Created by lei.shen on 2018/9/19.
 */
public class SingletonTest {

    public static void main(String[] args) {

        int size = 300;
        final CountDownLatch latch = new CountDownLatch(size);

        for(int i = 0; i < size; i++) {

            new Thread() {
                @Override
                public void run() {
                    try {
                        latch.await();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    //LazyTwo lazyTwo = LazyTwo.getInstance();
                    //System.out.println(System.currentTimeMillis() + " " + lazyTwo);

                    String classNmae = "com.bigShen.pattern.singleton.regist.RegistDemo";
                    Object obj = BeanFactory.getBean(classNmae);
                    System.out.println(obj);

                }
            }.start();

            System.out.println(latch.getCount());
            latch.countDown();

        }

    }

}
